package com.situ.service.user;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.situ.service.user.SysUserService;
import com.situ.dao.user.SysUserDao;
import com.situ.util.Assist;
import com.situ.entity.user.SysUser;
/**
 * SysUser的服务接口的实现类
 * 
 * @author 胡文 qq:986776
 *
 */
@Service
public class SysUserServiceImpl implements SysUserService {
	private final Logger LOG = LogManager.getLogger(this.getClass());

	@Autowired
	private SysUserDao sysUserDao;

/**
* 查询....
*/
	@Override
	public List<SysUser> find(SysUser value) {

		List<SysUser> result = sysUserDao.selectSysUserByObj(value);

		return result;
	}
    /**
* 根据id查询
*/
	@Override
	public SysUser findOne(Long id) {

		SysUser result = sysUserDao.selectSysUserById(id);

		return result;
	}

/**
* 添加不为空
*/
	@Override
	public SysUser saveNotNull(SysUser value) {
		if (value == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行将SysUser中属性值不为null的数据保存到数据库-->失败:对象不能为空");
			}
			return value;
		}
		if(value.getUsr_name() == null || value.getUsr_password() == null || value.getUsr_flag() == null  ){
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行将SysUser中属性值不为null的数据保存到数据库-->失败:存在不能为空的空值");
			}
			return value;
		}
		int result = sysUserDao.insertNotNullSysUser(value);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行将SysUser中属性值不为null的数据保存到数据库-->结果:", result);
		}
		return value;
	}
	@Override
    /**
* 修改不为空
*/
	public int updateNotNullById(SysUser value) {
		if (value == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行通过SysUser的id更新SysUser中属性不为null的数据-->失败:对象为null");
			}
			return 0;
		}
		int result = sysUserDao.updateNotNullSysUserById(value);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行通过SysUser的id更新SysUser中属性不为null的数据-->结果:", result);
		}
		return result;
	}
    /**
* 删除
*/
	@Override
	public int deleteById(Long id) {
		if (id == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行通过SysUser的id删除SysUser-->失败:id不能为空");
			}
			return 0;
		}
		int result = sysUserDao.deleteSysUserById(id);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行通过SysUser的id删除SysUser-->结果:", result);
		}
		return result;
	}

    @Override
    public List<SysUser> queryUsers() {
        return sysUserDao.query();
    }

    @Override
    public Map query(SysUser sysUser) {
        return sysUserDao.queryAllUsers(sysUser);
    }

    @Override
    public List<SysUser> queryByLike(SysUser queryByLike) {
        return sysUserDao.queryByLike(queryByLike);
    }

    @Override
    public SysUser queryByUsrId(int usrId) {
        return sysUserDao.queryByUsrId(usrId);
    }

    @Override
    public int myAdd(SysUser sysUser) {
        return sysUserDao.myAdd(sysUser);
    }

    @Override
    public int deleteUserById(int usrId) {
        return sysUserDao.deleteUserById(usrId);
    }

    @Override
    public int addUser(SysUser sysUser) {
        return sysUserDao.addUser(sysUser);
    }

    @Override
    public List<SysUser> selectflag(SysUser sysUser) {
        return sysUserDao.selestflag(sysUser);
    }

    @Override
    public int updateUser(SysUser sysUser) {
        return sysUserDao.updateUser(sysUser);
    }

    @Override
    public List<SysUser> findOne2() {

        List<SysUser> result = sysUserDao.selectSysUserById2();

        return result;
    }

    @Override
    public String queryusername(int id) {
        return sysUserDao.queryusername(id);
    }


}